<%@page contentType="text/html; charset=utf-8"%>
<%@ include file="../inc/TagLibs.jsp"%>
<html>
<%@ include file="../inc/Title.jsp"%>
<link href="/css/Query.css" rel="stylesheet" type="text/css">
<head>
<script src="/js/QueryList.js"></script>
<script src="/calendar/calendar.js"></script>
<script language="javascript">
	function doShow(id,type){
		var url;
		var strFeatures;
		if(type=="IMPREST"){
			url="/purchase/PurchaseBillEdit.ihtm?id="+id;
			strFeatures = "dialogWidth:900px;dialogHeight:700px;scroll:no;center:yes;status:no";
		}else{
			url="/finance/PayBillEdit.ihtm?id="+id;
			strFeatures = "dialogWidth:900px;dialogHeight:700px;scroll:no;center:yes;status:no";
		}
		
		var retValue=popDialog(url,strFeatures);
		if(retValue!=null && retValue!=""){
			window.location.reload(true);
		}
	}
	function showWin(w,h,url){
		var left=(window.screen.width-w)/2;
	    var top=(window.screen.height-64-h)/2;
		window.open(url,'_blank','top='+top+',left='+left+',status=no,menubar=no,resizable=no,scrollbars=yes,width='+w+',height='+h);
	}

	function popDialog(url,features){
		var frameUrl='/ModalDialog.ihtm?targetUrl='+encodeURIComponent(url);
		return showModalDialog(frameUrl,window,features);
	}

	function getDateStr(){
		var startDate=document.getElementById("start_date").value;
		if(startDate==null || startDate==''){
			alert("请选择开始日期");
			return;
		}else{
			var arr=startDate.split("-");
			if(arr.length==null || arr.length!=3){
				alert("开始日期格式不正确");
				return;
			}else if(isNaN(arr[0]) || isNaN(arr[1]) || isNaN(arr[2])){
				alert("开始日期格式不正确");
				return;
			}
		}
		var endDate=document.getElementById("end_date").value;
		if(endDate==null || endDate==''){
			alert("请选择结束日期");
			return;
		}else{
			var arr=endDate.split("-");
			if(arr.length==null || arr.length!=3){
				alert("结束日期格式不正确");
				return;
			}else if(isNaN(arr[0]) || isNaN(arr[1]) || isNaN(arr[2])){
				alert("结束日期格式不正确");
				return;
			}
		}
		return "start_date="+startDate+"&end_date="+endDate;
	}
	function doSearch(){
		var str;
		if(document.getElementById("moreTbody").style.display==""){//高级
			str="search_type=1";
			if(document.getElementById("cb_pay_date").checked){
				var dateStr=getDateStr();
				if(dateStr!=null && dateStr!=""){
					if(str!=""){
						str=str+"&";
					}
					str=str+"cb_pay_date=1&"+dateStr;
				}else{
					return;
				}
			}
			if(document.getElementById("cb_manager").checked){
				var managerName=document.getElementById("manager_name").value;
				if(managerName==null || managerName==""){
					alert("请输入经办人姓名");
					return;
				}
				if(str!=""){
					str=str+"&";
				}
				str=str+"cb_manager=1&manager_name="+encodeURIComponent(managerName);
			}
			if(document.getElementById("cb_est").checked){
				var estName=document.getElementById("est_name").value;
				if(estName==null || estName==""){
					alert("请输入收款单位");
					return;
				}
				if(str!=""){
					str=str+"&";
				}
				str=str+"cb_est=1&est_name="+encodeURIComponent(estName);
			}
			
			if(document.getElementById("cb_cost").checked){
				var minCost=document.getElementById("min_cost").value;
				if(minCost==null || minCost==""){
					alert("请输入最小金额");
					return;
				}else if(isNaN(minCost)){
					alert("最小金额只能是数字");
					return;
				}
				var maxCost=document.getElementById("max_cost").value;
				if(maxCost==null || maxCost==""){
					alert("请输入最大金额");
					return;
				}else if(isNaN(maxCost)){
					alert("最大金额只能是数字");
					return;
				}
				if(str!=""){
					str=str+"&";
				}
				str=str+"cb_cost=1&min_cost="+minCost+"&max_cost="+maxCost;
			}
			if(document.getElementById("cb_ts").checked){
				var tsId=document.getElementById("ts_id").value;
				if(tsId==null || tsId=="" || tsId=="0"){
					alert("请选择帐套");
					return;
				}
				if(str!=""){
					str=str+"&";
				}
				str=str+"cb_ts=1&ts_id="+tsId;
			}
		}else{//快速
			var dateStr=getDateStr();
			if(dateStr!=null && dateStr!=""){
				str="search_type=2&"+dateStr;
			}else{
				return;
			}
		}
		window.location="/finance/PayCostList.ihtm?"+str;
	}
	function getSearchCondition(){
		var searchType="${searchType}";
		var startDate="${startDate}";
		var endDate="${endDate}";
		var str="search_type="+searchType;
		if(searchType=="1"){//高级
			var cbPayDate="${cbPayDate}";
			if(cbPayDate=="1"){
				str=str+"&cb_pay_date=1&start_date="+startDate+"&end_date="+endDate;
			}
			
			var cbManager="${cbManager}";
			var managerName="${managerName}";
			if(cbManager=="1"){
				str=str+"&cb_manager=1&manager_name="+encodeURIComponent(managerName);
			}
			
			var cbEst="${cbEst}";
			var estName="${estName}";
			if(cbEst=="1"){
				str=str+"&cb_est=1&est_name="+encodeURIComponent(estName);
			}
			
			var cbCost="${cbCost}";
			var minCost="${minCost}";
			var maxCost="${maxCost}";
			if(cbCost=="1"){
				str=str+"&cb_cost=1&min_cost="+minCost+"&max_cost="+maxCost;
			}
			
			var cbTs="${cbTs}";
			var tsId="${tsId}";
			if(cbTs=="1"){
				str=str+"&cb_ts=1&ts_id="+tsId;
			}
		}else{//快速
			str=str+"&start_date="+startDate+"&end_date="+endDate;
		}
		return str;
	}
	function checkCbChange(obj){
		if(obj.id=="cb_pay_date"){
			if(obj.checked){
				document.getElementById("start_date").disabled=false;
				document.getElementById("end_date").disabled=false;
			}else{
				document.getElementById("start_date").disabled=true;
				document.getElementById("end_date").disabled=true;
			}
		}else if(obj.id=="cb_manager"){
			if(obj.checked){
				document.getElementById("manager_name").disabled=false;
			}else{
				document.getElementById("manager_name").disabled=true;
			}
		}else if(obj.id=="cb_est"){
			if(obj.checked){
				document.getElementById("est_name").disabled=false;
			}else{
				document.getElementById("est_name").disabled=true;
			}
		}else if(obj.id=="cb_cost"){
			if(obj.checked){
				document.getElementById("min_cost").disabled=false;
				document.getElementById("max_cost").disabled=false;
			}else{
				document.getElementById("min_cost").disabled=true;
				document.getElementById("max_cost").disabled=true;
			}
		}else if(obj.id=="cb_ts"){
			if(obj.checked){
				document.getElementById("ts_id").disabled=false;
			}else{
				document.getElementById("ts_id").disabled=true;
			}
		}
	}
	function doDownload(){
		var str=getSearchCondition();
		window.location="/finance/PayCostList.ihtm?content_type=EXCEL&"+str;
	}
	function checkInput(){
		if(window.event.keyCode==13){
			doSearch();
		}
	}
	function showMore(){
		if(document.getElementById("moreTbody").style.display==""){//高级变低级
			document.getElementById("cb_pay_date").style.display="none";
			document.getElementById("start_date").disabled=false;
			document.getElementById("end_date").disabled=false;
			document.getElementById("sSearchButton").style.display="";
			if(document.getElementById("sDownloadButton")!=null){
				document.getElementById("sDownloadButton").style.display="";
			}
			if(document.getElementById("sPrintButton")!=null){
				document.getElementById("sPrintButton").style.display="";
			}
			document.getElementById("moreTbody").style.display="none";
			document.getElementById("moreDiv").className="search-con";
		}else{
			document.getElementById("cb_pay_date").style.display="";
			if(!document.getElementById("cb_pay_date").checked){
				document.getElementById("start_date").disabled=true;
				document.getElementById("end_date").disabled=true;
			}
			document.getElementById("sSearchButton").style.display="none";
			if(document.getElementById("sDownloadButton")!=null){
				document.getElementById("sDownloadButton").style.display="none";
			}
			if(document.getElementById("sPrintButton")!=null){
				document.getElementById("sPrintButton").style.display="none";
			}
			document.getElementById("moreTbody").style.display="";
			document.getElementById("moreDiv").className="search-on";
		}
	}
	function doPrint(){
		var str=getSearchCondition();
		window.location="/finance/PayCostList.ihtm?content_type=PRINT&"+str;
	}
</script>
</head>
<body oncontextmenu="return false"  class="sheet">
<div class="sheet-main" style="width:860px">
  <div class="sheet-top">
    <div class="content">
      <h2>采购付款一览表</h2>
      <p>包括进货单/采购退货的预付款，以及给供应商的付款</p>
    </div>
  </div>
  <div class="sheet-list">
    <div class="search-business">
      <div class="content">
        <table width="748">
			<tbody>
	        <tr>
			  <td width="20"><input name="" type="checkbox" name="cb_pay_date" id="cb_pay_date" onClick="checkCbChange(this);" <c:if test="${cbPayDate=='1' || searchType=='2'}">checked="true"</c:if> style="display:none" /></td>
	          <th width="70">付款日期</th>
	          <td>
			  	<input type="text" class="f-text" maxlength="15" onKeyUp="checkInput();" id="start_date" name="start_date" value="${startDate}" <c:if test="${searchType=='1' && cbPayDate!='1'}">disabled</c:if>>
				<img src="/images/calendar.gif" style="cursor:hand" onClick="fPopUpCalendarDlg('/calendar/','start_date');">
	            至
				<input type="text" class="f-text" maxlength="15" onKeyUp="checkInput();" id="end_date" name="end_date" value="${endDate}" <c:if test="${searchType=='1' && cbPayDate!='1'}">disabled</c:if>>
				<img src="/images/calendar.gif" style="cursor:hand" onClick="fPopUpCalendarDlg('/calendar/','end_date');">
			  </td>
	          <td width="240" align="right">
			  	<input type="button" value="查 询" onClick="doSearch();" class="buttom search-but" id="sSearchButton" name="sSearchButton">
				<input type="button" value="导 出" onClick="doDownload();" class="buttom search-out" id="sDownloadButton" name="sDownloadButton">
				<input type="button" value=" 打印" onClick="doPrint();" class="buttom search-print" id="sPrintButton" name="sPrintButton">
			  </td>
	        </tr>
	      </tbody>
	      <tbody id="moreTbody" style="display:none">
	        <tr>
	          <td><input type="checkbox" name="cb_manager" id="cb_manager" onClick="checkCbChange(this);" <c:if test="${cbManager=='1'}">checked="true"</c:if>></td>
	          <th>经办人员</th>
	          <td>
			  	<input type="text" class="f-text" maxlength="15" name="manager_name" id="manager_name" onKeyUp="checkInput();" value="${managerName}" <c:if test="${cbManager!='1'}">disabled="true"</c:if>>
			  </td>
	          <td></td>
	        </tr>
	        <tr>
	          <td><input type="checkbox" name="cb_est" id="cb_est" onClick="checkCbChange(this);" <c:if test="${cbEst=='1'}">checked="true"</c:if>></td>
	          <th>收款单位</th>
	          <td>
			  	<input type="text" class="f-text" maxlength="50" name="est_name" id="est_name" onKeyUp="checkInput();" value="${estName}" <c:if test="${cbEst!='1'}">disabled="true"</c:if>>
			  </td>
	          <td></td>
	        </tr>
	        <tr>
	          <td><input type="checkbox" name="cb_cost" id="cb_cost" onClick="checkCbChange(this);" <c:if test="${cbCost=='1'}">checked="true"</c:if>></td>
	          <th>付款金额</th>
	          <td>
			  	<input type="text" class="f-text" maxlength="15" onKeyUp="checkInput();" id="min_cost" name="min_cost" value="${minCost}" <c:if test="${cbCost!='1'}">disabled="true"</c:if>>
				至<input type="text" class="f-text" maxlength="15" onKeyUp="checkInput();" id="max_cost" name="max_cost" value="${maxCost}" <c:if test="${cbCost!='1'}">disabled="true"</c:if>>
			  </td>
	          <td></td>
	        </tr>
			<tr>
	          <td><input type="checkbox" name="cb_ts" id="cb_ts" onClick="checkCbChange(this);" <c:if test="${cbTs=='1'}">checked="true"</c:if>></td>
	          <th>账套</th>
	          <td>
				  <select name="ts_id" id="ts_id" <c:if test="${cbTs!='1'}">disabled="true"</c:if>>
					  <option value="0">==请选择==</option>
					  <c:forEach var="item" items="${tsList}">
					  	<option value="${item.id}" <c:if test="${tsId==item.id}">selected</c:if>>${item.title}</option>
					  </c:forEach>
				  </select>
			  </td>
	          <td></td>
	        </tr>
	        <tr>
	          <td></td>
	          <th></th>
	          <td style="padding-top:6px;">
			  	<input type="button"  value="查 询" onClick="doSearch();"  class="buttom search-but">
				<input type="button"  value="导 出" onClick="doDownload();" class="buttom search-out">
				<input type="button" value=" 打印" onClick="doPrint();" class="buttom search-print">
			  </td>
	          <td>
			  </td>
	        </tr>
	      </tbody>
		</table>      	 
      </div>
	  <div class="search-con" id="moreDiv"><a style="cursor:hand" onClick="showMore();"><c></a></div>
	  <%@include file="../inc/AlertMsg.jsp"%>
	  <div class="cue-info">
		<span>付款累计：${total}元&nbsp;&nbsp;</span>
      </div>	  
      	
	
     <div class="table-list">
        <table width="100%">
          <tr>
		  	<th  width="13%">预付日期</th>
			<th  width="20%">单号</th>
			<th  width="5%">进/退</th>
			<th  width="21%">供应商</th>
			<th  width="12%">金额（元）</th>
			<th  width="12%">银行账户</th>							
			<th  width="10%">经办人</th>						
			<th  width="10%">操作</th>
			</tr>
			<c:if test="${fn:length(imprestList)==0}">
			<tr>
				<td colspan="8">没有预付数据</td>
			</tr>
			</c:if>
			<c:if test="${fn:length(imprestList)>0}">
			<c:forEach var="item" items="${imprestList}" varStatus="i">
				<tr  <c:if test="${item[0].purchaseBill.billType=='BACK'}">style="color:#ff0000"</c:if>>
					<td ><fmt:formatDate value="${item[0].purchaseBill.purchaseDate}" pattern="yyyy-MM-dd"/></td>
					<td >${item[0].purchaseBill.billCode}</td>
					<td >
						<c:if test="${item[0].purchaseBill.billType=='BUY'}">进</c:if>
						<c:if test="${item[0].purchaseBill.billType=='BACK'}">退</c:if>
					</td>
					<td >${item[1].estName}</td>
					<td >
						<c:if test="${item[0].purchaseBill.billType=='BUY'}">${item[0].purchaseBill.imprest}</c:if>
						<c:if test="${item[0].purchaseBill.billType=='BACK'}">${0-item[0].purchaseBill.imprest}</c:if>
					</td>
					<td><commonTag:showSimpleObjectName list="${bankAccountList}" objectId="${item[0].purchaseBill.bankAccountId}" /></td>						
					<td >${item[0].purchaseBill.managerName}</td>
					<td>
						<a href="javascript:doShow('${item[0].purchaseBill.id}','IMPREST');">查看</a>
					</td>
				</tr>
			</c:forEach>
			</c:if>
		 </table>
	   </div>
		 <div class="blank12"></div>
     <div class="table-list">
        <table width="100%">
          <tr>
		  	<th  width="13%">付款日期</th>
			<th  width="20%">单号</th>
			<th  width="26%">供应商</th>
			<th  width="12%">金额（元）</th>
			<th  width="12%">银行账户</th>
			<th  width="10%">经办人</th>
			<th  width="10%">操作</th>
			</tr>
			<c:if test="${fn:length(payList)==0}">
			<tr>
				<td colspan="8">没有付款数据</td>
			</tr>
			</c:if>
			<c:if test="${fn:length(payList)>0}">
			<c:forEach var="item" items="${payList}" varStatus="i">
				<tr >
					<td ><fmt:formatDate value="${item[0].payBill.payDate}" pattern="yyyy-MM-dd"/></td>
					<td >${item[0].payBill.billCode}</td>
					<td >${item[1].estName}</td>
					<td >${item[0].payBill.cost}</td>
					<td ><commonTag:showSimpleObjectName list="${bankAccountList}" objectId="${item[0].payBill.bankAccountId}" /></td>
					<td >${item[0].payBill.managerName}</td>
					<td>
						<a href="javascript:doShow('${item[0].payBill.id}','PAY');">查看</a>
					</td>
				</tr>
			</c:forEach>
			</c:if>
		</table>
     </div>
    </div>
  </div>
</div>	
</body>
</html>